package l1j.opqlo.NewSystem.Attack;

import static l1j.server.server.model.skill.L1SkillId.BONE_BREAK;
import static l1j.server.server.model.skill.L1SkillId.REDUCTION_ARMOR;
import static l1j.server.server.model.skill.L1SkillId.烏骨雞湯;

import java.util.ArrayList;
import java.util.ConcurrentModificationException;

import l1j.opqlo.Server.L1World.L1World;
import l1j.opqlo.Timer.Controler.Server.ServerWarExecutor;
import l1j.server.server.ActionCodes;
import l1j.server.server.model.L1CastleLocation;
import l1j.server.server.model.L1Character;
import l1j.server.server.model.L1Chaser;
import l1j.server.server.model.Instance.L1MonsterInstance;
import l1j.server.server.model.Instance.L1NpcInstance;
import l1j.server.server.model.Instance.L1PcInstance;
import l1j.server.server.model.Instance.L1PetInstance;
import l1j.server.server.model.Instance.L1SummonInstance;
import l1j.server.server.model.gametime.L1GameTimeClock;
import l1j.server.server.model.poison.L1DamagePoison;
import l1j.server.server.model.poison.L1ParalysisPoison;
import l1j.server.server.model.poison.L1SilencePoison;
import l1j.server.server.model.skill.L1SkillUse;
import l1j.server.server.serverpackets.S_AttackMissPacket;
import l1j.server.server.serverpackets.S_AttackPacketForNpc;
import l1j.server.server.serverpackets.S_Paralysis;
import l1j.server.server.serverpackets.S_SkillSound;
import l1j.server.server.serverpackets.S_UseArrowSkill;
import l1j.server.server.serverpackets.S_UseAttackSkill;
import l1j.server.server.types.Point;
import l1j.server.server.utils.Random;

//耐性 (>> 1: 除)  (<< 1: 乘)
public class L1AttackNpc extends L1AttackModel {

	public L1AttackNpc(final L1NpcInstance attacker, final L1Character target) {
		if (attacker == null) {
			return;
		}
		if (target == null) {
			return;
		}
		if (target.isDead()) {
			return;
		}
		if (target.getCurrentHp() <= 0) {
			return;
		}
		this._npc = attacker;
		if (target instanceof L1PcInstance) {
			this._targetPc = (L1PcInstance) target;
			this._calcType = NPC_PC;

		} else if (target instanceof L1NpcInstance) {
			this._targetNpc = (L1NpcInstance) target;
			this._calcType = NPC_NPC;
		}
		this._target = target;
		this._targetId = target.getId();
		this._targetX = target.getX();
		this._targetY = target.getY();
	}

	@Override
	public final void action() {
		// new AttackAction().actionPc(_npc, _target, _isHit, getActId()
		// ,getGfxId());
		// final int _npcObjectId = _npc.getId();
		if (this._npc == null) {
			return;
		}
		int _Actid = this.getActId();
		final int _gfxid = this.getGfxId();
		int bowActId = 0;

		this._npc.setHeading(this._npc.targetDirection(this._targetX,this._targetY)); // 向きのセット

		// ターゲットとの距離が2以上あれば遠距離攻撃
		final boolean isLongRange = this._npc.getLocation()
				.getTileLineDistance(new Point(this._targetX, this._targetY)) > 1;

		bowActId = this._npc.getNpcTemplate().getBowActId();

		if (_Actid == 0) {
			_Actid = ActionCodes.ACTION_Attack;
		}

		// 距離が2以上、攻撃者の弓のアクションIDがある場合は遠攻撃
		if (isLongRange && bowActId > 0) {
			this._npc.broadcastPacketAll(new S_UseArrowSkill(this._npc,this._targetId, bowActId, this._targetX, this._targetY,this._isHit));
		} else {
			if (this._isHit) {
				if (_gfxid > 0) {
					this._npc.broadcastPacketAll(new S_UseAttackSkill(this._npc,this._targetId, _gfxid, this._targetX,this._targetY, _Actid));
//					this._target.broadcastPacketExceptTargetSight(new S_DoActionGFX(this._targetId,ActionCodes.ACTION_Damage), this._npc);
				} else {
					this._npc.broadcastPacketAll(new S_AttackPacketForNpc(this._target, this._npc.getId(), _Actid));
//					this._target.broadcastPacketExceptTargetSight(new S_DoActionGFX(this._targetId,ActionCodes.ACTION_Damage), this._npc);
				}
			} else {
				if (_gfxid > 0) {
					this._npc.broadcastPacketAll(new S_UseAttackSkill(this._npc,this._targetId, _gfxid, this._targetX,this._targetY, _Actid, 0));
				} else {
					this._npc.broadcastPacketAll(new S_AttackMissPacket(this._npc,this._targetId, _Actid));
				}
			}
		}
	}

	/**
	 * ククルカン武器のチェイサーを土屬性でテーベチェイサーと同じダメージ計算式で實裝 テーベチェイサーの属性が無属性になっていたため、土属性に修正
	 * チェイサーの発動率とダメージを本鯖準拠に修正 チェイサーのダメージが計算される度にイレースマジックの効果を消去するように修正
	 */
	// ■■■■ チェイサーによる攻撃を付加 ■■■■
	@Override
	public final void addChaserAttack() {
		final L1Chaser chaser = new L1Chaser(this._pc, this._target);
		chaser.begin();

	}

	/**
	 * ＮＰＣの毒攻撃を付加
	 *
	 * @param attacker
	 * @param target
	 */
	private final void addNpcPoisonAttack(final L1Character attacker,
			final L1Character target) {
		final int pp = this._npc.getNpcTemplate().get_poisonatk();
		if (pp != 0) { // 毒攻撃あり
			int chance = 30;
			if (pp == 7) {
				chance = 80;
			} else if (pp == 8) {
				chance = 100;
			}
			if (chance >= Random.nextInt(100) + 1) { // 15%の確率で毒攻撃

				switch (pp) {
				case 1: // 通常毒
					L1DamagePoison.doInfection(attacker, target, 3000, 5, true);
					break;
				case 2:// 沈黙毒
					L1SilencePoison.doInfection(target);
					break;
				case 4:// 麻痺毒
						// 20秒後に45秒間麻痺
					L1ParalysisPoison.doInfection(target, 20000, 45000);
					break;
				case 5:// opqlo 血減半
					for (final L1Character pc : L1World.getInstance()
							.getVisiblePlayer(this._npc)) {
						final int hp = pc.getCurrentHp() >> 1; // opqlo 位移運算 >>
																// =除 <<=乘
						if (hp == 0) {
							pc.setCurrentHp(1);
						} else {
							pc.setCurrentHp(hp);
						}
					}
					break;
				case 6: // opqlo 骷髏毀壞3秒
					if (target.hasSkillEffect(208)) {
						return;
					}
					target.setSkillEffect(BONE_BREAK, 3000);// BONE_BREAK 骷髏毀壞3秒
					if (target instanceof L1PcInstance) {
						final L1PcInstance pc = (L1PcInstance) target;
						pc.sendPackets(new S_Paralysis(S_Paralysis.TYPE_STUN,
								true));
					} else if (target instanceof L1MonsterInstance
							|| target instanceof L1SummonInstance
							|| target instanceof L1PetInstance) {
						final L1NpcInstance npc = (L1NpcInstance) target;
						npc.setParalyzed(true);
					}
					break;
				case 7: // opqlo 超痛劇毒(無法解毒與抵抗)
					final int dmg = (int) (target.getMaxHp() * 0.02);
					L1DamagePoison.doInfection(attacker, target, 1500, dmg,
							true);
					break;
				case 8: // opqlo BOSS範圍組合技
					final int UseType = Random.nextInt(100) + 1;
					int skillid = 0;
					boolean Buff = false;
					if (UseType >= 75) {
						// skillid =74;// 流星雨
						skillid = 100001;// 雷霆風暴
					} else if (UseType >= 50) {
						skillid = 100001;// 雷霆風暴
					} else if (UseType >= 25) {
						// skillid =77;// 究極光裂術
						skillid = 100001;// 雷霆風暴
					} else {
						skillid = 64;// 魔法封印
						Buff = true;
					}
					final ArrayList<L1Character> acquisitorList = this._npc.getHateList().toTargetArrayList();
					final ArrayList<Integer> hateList = this._npc.getHateList().toHateArrayList();

					if (acquisitorList.size() != hateList.size()) {
						return;
					}
					L1Character acquisitor;
					final L1SkillUse skillUse = new L1SkillUse();
					boolean canUseSkill = false;
					for (int i = hateList.size() - 1; i >= 0; i--) {
						acquisitor = acquisitorList.get(i);
						if (acquisitor instanceof L1PcInstance) {
							if (acquisitor != null && !acquisitor.isDead()) {
								final L1PcInstance pc = (L1PcInstance) acquisitor;
								canUseSkill = skillUse.checkUseSkill(null,
										skillid, pc.getId(), pc.getX(),
										pc.getY(), null, 0,
										L1SkillUse.TYPE_GMBUFF, this._npc);
								if (canUseSkill) {
									if (!Buff) {
										skillUse.setLeverage(this._npc.getInt() * 10);
										skillUse.handleCommands(pc, skillid,
												pc.getId(), pc.getX(),
												pc.getX(), null, 0,
												L1SkillUse.TYPE_GMBUFF);
									} else {
										skillUse.handleCommands(null, skillid,
												pc.getId(), pc.getX(),
												pc.getY(), null, 0,
												L1SkillUse.TYPE_GMBUFF,
												this._npc);
									}
								} else {
									acquisitorList.remove(i);
									hateList.remove(i);
								}
							} else { // nullだったり死んでいたら排除
								acquisitorList.remove(i);
								hateList.remove(i);
							}
						}
					}
				}

			}
		} else if (this._npc.getNpcTemplate().get_paralysisatk() != 0) { // 麻痺攻撃あり
		}
	}

	/* ■■■■■■■■■■■■■■■ ダメージ算出 ■■■■■■■■■■■■■■■ */

	@Override
	public final int calcDamage() {
		if (this._calcType == NPC_PC) {
			this._damage = this.calcPcDamage();
			if(this._targetPc !=null && this._targetPc.hasSkillEffect(烏骨雞湯)){
				this._damage *= 0.9;
			}
		} else if (this._calcType == NPC_NPC) {
			this._damage = this.calcNpcDamage();
		}
		return this._damage;
	}

	/**
	 * 命中判定
	 */
	@Override
	public boolean calcHit() {
		if (this._target == null) {// 物件遺失
			this._isHit = false;
			return this._isHit;
		}
		if(this._npc.getNpcId() == 2000259){//[自爆]爆漿蟻
			if(this._calcType == NPC_NPC) {
				this._targetNpc.receiveDamage(this._npc, 5000);
			}else{
				this._targetPc.receiveDamage(this._npc, 5000, false);
			}
			this._npc.broadcastPacketX10(new S_SkillSound(this._npc.getId() , 5131));
			this._npc.setCurrentHp(1);
			this._npc.receiveDamage(this._target, 1);
			return false;
		}
		switch (this._calcType) {
		case NPC_PC:
			this._isHit = this.calcPcHit();
			break;

		case NPC_NPC:
			this._isHit = this.calcNpcHit();
			break;
		}
		return this._isHit;
	}

	/**
	 * NPC對NPC傷害
	 *
	 * @return
	 */
	private int calcNpcDamage() {
		if (this._targetNpc == null) {
			return 0;
		}

		// 傷害為0
		if (dmg0(this._targetNpc)) {
			this._isHit = false;
			return 0;
		}

		final int lvl = this._npc.getLevel();
		double dmg = 0;

		if (this._npc instanceof L1PetInstance) {
			dmg = Random.nextInt(this._npc.getNpcTemplate().get_level())
					+ this._npc.getStr() / 2 + 1;
			// dmg += (lvl / 16); // 每16級追加1點攻擊力// TEST
			dmg += lvl / 14; // 每14級追加1點攻擊力 XXX
			dmg += ((L1PetInstance) this._npc).getDamageByWeapon();

		} else {
			final Integer dmgStr = L1AttackList.STRD.get((int) this._npc
					.getStr());
			dmg = Random.nextInt(lvl) + this._npc.getStr() / 2 + dmgStr;
		}

		if (this.isUndeadDamage()) {
			dmg *= 1.1;
		}

		dmg = dmg * this.getLeverage() / 10;

		this.addNpcPoisonAttack(this._npc, this._targetNpc);

		/********************* 攻擊力減少公式 *************************/

		dmg -= this.calcNpcDamageReduction();// 減傷

		if (this._npc.isWeaponBreaked()) { // ＮＰＣがウェポンブレイク中。
			dmg /= 2;
		}

		final int DmgReduce = this._targetNpc.getDmgReduceRate();
		if (DmgReduce >= 100) {
			dmg = 1;

		} else if (DmgReduce > 0) { // opqlo 怪物減傷倍率
			dmg = Math.max(dmg / DmgReduce, 1);
		}

		/********* 幽能攻擊公式(直接傷害) *********/
		// opqlo 額外攻擊力
		final int ExtraDmg = this._npc.getExtraDmg();

		dmg += ExtraDmg;

		// ペット、サモンからプレイヤーに攻撃
		boolean isNowWar = false;
		final int castleId = L1CastleLocation
				.getCastleIdByArea(this._targetNpc);
		if (castleId > 0) {
			isNowWar = ServerWarExecutor.get().isNowWar(castleId);
		}
		if (!isNowWar) {
			if (this._npc instanceof L1PetInstance) {
				if (this._targetNpc instanceof L1PetInstance
						|| this._targetNpc instanceof L1SummonInstance) {
					dmg = (int) dmg >> 6;
				}
			} else if (this._npc instanceof L1SummonInstance) {
				if (this._targetNpc instanceof L1PetInstance
						|| this._targetNpc instanceof L1SummonInstance) {
					final L1SummonInstance summon = (L1SummonInstance) this._npc;
					if (summon.isExsistMaster()) {
						// dmg /= 8;
						dmg = (int) dmg >> 6;
					}
				}
			}
		}

		// opqlo 額外攻擊力
		if (dmg <= 0) {
			this._isHit = false;
		}

		return (int) dmg;
	}

	/**
	 * NPC對NPC命中
	 *
	 * @return
	 */
	private boolean calcNpcHit() {

		// 傷害為0
		if (dmg0(this._targetNpc)) {
			return false;
		}

		// this._hitRate += this._npc.getLevel();// XXX
		this._hitRate += this._npc.getLevel() + 3;

		if (this._npc instanceof L1PetInstance) { // 寵物武器命中追加
			this._hitRate += ((L1PetInstance) this._npc).getHitByWeapon();
		}
		this._hitRate += this._npc.getHitup();

		int attackerDice = Random.nextInt(20) + 1 + this._hitRate - 3;

		// 技能增加閃避
		attackerDice += attackerDice(this._targetNpc);

		int defenderDice = 0;

		// TODO 閃避率byajackk2001
		attackerDice -= this._targetNpc.getDodge()
				+ this._targetNpc.getNdodge();
		// TODO 閃避率byajackk2001
		// final int ac = Math.max(-127, _targetNpc.getAc());
		final int ac = this._targetNpc.getAc();
		final int defenderValue = ac * -1;

		if (ac >= 0) {
			defenderDice = 10 - this._targetNpc.getAc();
		} else if (ac < 0) {
			defenderDice = 10 + Random.nextInt(defenderValue) + 1;
		}

		final int fumble = this._hitRate;
		final int critical = this._hitRate + 19;

		if (attackerDice <= fumble) {
			this._hitRate = 15;

		} else if (attackerDice >= critical) {
			this._hitRate = 100;

		} else {
			if (attackerDice > defenderDice) {
				this._hitRate = 100;

			} else if (attackerDice <= defenderDice) {
				this._hitRate = 15;
			}
		}

		final int rnd = Random.nextInt(100) + 1;
		return this._hitRate >= rnd;
	}

	/**
	 * NPC對PC傷害
	 *
	 * @return
	 */
	private int calcPcDamage() {

		if (this._targetPc == null) {
			return 0;
		}
		// 傷害為0
		if (dmg0(this._targetPc)) {
			this._isHit = false;
			return 0;
		}

		final int lvl = this._npc.getLevel();
		double dmg = 0D;

		final Integer dmgStr = L1AttackList.STRD.get((int) this._npc.getStr());
		dmg = Random.nextInt(lvl) + this._npc.getStr() * 0.8 + dmgStr;

		if (this._npc instanceof L1PetInstance) {
			dmg += lvl / 7; // 每7級追加1點攻擊力 XXX
			dmg += ((L1PetInstance) this._npc).getDamageByWeapon();
		}

		dmg += this._npc.getDmgup();

		if (this.isUndeadDamage()) {
			dmg *= 1.1;
		}

		dmg = dmg * this.getLeverage() / 10;

		/********* 幽能攻擊公式(直接傷害) *********/
		// opqlo 額外攻擊力
		final int ExtraDmg = this._npc.getExtraDmg();
		if (dmg >= 0) {
			dmg += ExtraDmg;
		} else if (Random.nextBoolean()) {
			final int ddmg = ExtraDmg / 2;
			dmg = Random.nextInt(ddmg) + ddmg;
		}
		// opqlo 額外攻擊力
		/********************* 攻擊力減少公式 *************************/

		dmg -= this.calcPcDefense();// 被攻擊者防禦力傷害直減低

		if (this._npc.isWeaponBreaked()) { // ＮＰＣがウェポンブレイク中。
			dmg /= 2;
		}
		/** 娃娃增加減傷opqlo改寫 **/
		dmg -= this._targetPc.getDamageReductionByArmor()
				+ this._targetPc.getDollList().getDamageReduction(); // 減傷

		if (this._targetPc.hasSkillEffect(REDUCTION_ARMOR)) {
			final int targetPcLvl = Math.max(this._targetPc.getLevel(), 50);
			dmg -= (targetPcLvl - 50) / 5 + 1;
		}

		boolean dmgX2 = false;// 傷害除2
		// 取回技能
		if (!this._targetPc.getSkillisEmpty()
				&& this._targetPc.getSkillEffect().size() > 0) {
			try {
				for (final Integer key : this._targetPc.getSkillEffect()) {
					final Integer integer = L1AttackList.SKD3.get(key);
					if (integer != null) {
						if (integer.equals(key)) {
							dmgX2 = true;

						} else {
							dmg += integer;
						}
					}
				}

			} catch (final ConcurrentModificationException e) {
				// 技能取回發生其他線程進行修改
			} catch (final Exception e) {
				// _log.error(e.getLocalizedMessage(), e);
			}
		}

		if (dmgX2) {
			dmg /= 2;
		}
		// }

		// ペット、サモンからプレイヤーに攻撃
		boolean isNowWar = false;
		final int castleId = L1CastleLocation.getCastleIdByArea(this._targetPc);
		if (castleId > 0) {
			isNowWar = ServerWarExecutor.get().isNowWar(castleId);
		}
		if (!isNowWar) {
			if (this._npc instanceof L1PetInstance) {
				dmg = (int) dmg >> 6;
			} else if (this._npc instanceof L1SummonInstance) {
				final L1SummonInstance summon = (L1SummonInstance) this._npc;
				if (summon.isExsistMaster()) {
					// dmg /= 8;
					dmg = (int) dmg >> 6;
				}
			}
		}

		if (dmg <= 0) {
			this._isHit = false;
		}

		this.addNpcPoisonAttack(this._npc, this._targetPc);

//		if (this._targetPc.hasSkillEffect(防禦月餅) && Random.nextBoolean()) {
//			dmg = (int) dmg >> 3; // 除以8
//		}
		return (int) dmg;
	}

	/**
	 * NPC對PC命中
	 *
	 * @return
	 */
	private boolean calcPcHit() {

		// 傷害為0
		if (dmg0(this._targetPc)) {
			return false;
		}

		// this._hitRate += this._npc.getLevel();// XXX
		this._hitRate += this._npc.getLevel() + 5;

		if (this._npc instanceof L1PetInstance) { // 寵物武器命中追加
			this._hitRate += ((L1PetInstance) this._npc).getHitByWeapon();
		}

		this._hitRate += this._npc.getHitup();

		int attackerDice = Random.nextInt(20) + 1 + this._hitRate - 1;

		// 技能增加閃避
		attackerDice += attackerDice(this._targetPc);

		int defenderDice = 0;

		// TODO 閃避率byajackk2001
		attackerDice += this._targetPc.getNdodge() - this._targetPc.getDodge();
		// TODO 閃避率byajackk2001

		final int defenderValue = this._targetPc.getAc() * -1;

		if (this._targetPc.getAc() >= 0) {
			defenderDice = 10 - this._targetPc.getAc();
		} else if (this._targetPc.getAc() < 0) {
			defenderDice = 10 + Random.nextInt(defenderValue) + 1;
		}

		// 基礎命中
		final int fumble = this._hitRate;
		// 基礎命中 + 19
		final int critical = this._hitRate + 19;

		if (attackerDice <= fumble) {
			this._hitRate = 15;

		} else if (attackerDice >= critical) {
			this._hitRate = 100;

		} else {
			// 防禦力抵銷
			if (attackerDice > defenderDice) {
				this._hitRate = 100;

			} else if (attackerDice <= defenderDice) {
				this._hitRate = 15;
			}
		}

		if (this._npc instanceof L1PetInstance
				|| this._npc instanceof L1SummonInstance) {
			// 目標在安區、攻擊者在安區、NOPVP
			if (this._targetPc.getZoneType() == 1
					|| this._npc.getZoneType() == 1
					|| this._targetPc.checkNonPvP(this._targetPc, this._npc)) {
				this._hitRate = 0;
			}
		}
		// TODO 魔法娃娃DB化
		// TODO マジックドール効果 - ダメージ回避
		/** 娃娃增加迴避率opqlo改寫 **/
		if (this._targetPc.getDollList().getdmgEvasion() > Random.nextInt(100) + 1) {
			this._hitRate = 0;
			this._npc.broadcastPacketX8(new S_SkillSound(this._targetId, 6320));
		}
		// TODO 魔法娃娃DB化
		final int rnd = Random.nextInt(100) + 1;

		// NPCの攻撃レンジが10以上の場合で、2以上離れている場合弓攻撃とみなす
		if (this._npc.getNpcTemplate().get_ranged() >= 10
				&& this._hitRate > rnd
				&& this._npc.getLocation().getTileLineDistance(
						new Point(this._targetX, this._targetY)) >= 2) {
			return this.calcErEvasion();
		}
		return this._hitRate >= rnd;
	}

	/* ■■■■■■■■■■■■■■ 攻撃モーション送信 ■■■■■■■■■■■■■■ */

	@Override
	public void calcStaffOfMana() {
		// TODO Auto-generated method stub

	}

	/* ■■■■■■■■■■■■■■■ 計算結果反映 ■■■■■■■■■■■■■■■ */

	@Override
	public final void commit() {
		if (this._isHit) {
			if (this._calcType == NPC_PC) {
				this.commitPc();
				return;
			} else if (this._calcType == NPC_NPC) {
				this.commitNpc();
				return;
			}
		}
	}

	/**
	 * 反擊屏障的傷害反擊
	 */
	@Override
	public void commitCounterBarrier() {
		final int damage = this.calcCounterBarrierDamage();
		if (damage == 0) {
			return;
		}
		this._npc.receiveDamage(this._targetPc, damage);

	}
	// ●●●● ＮＰＣに計算結果を反映 ●●●●
	private final void commitNpc() {
		if (this._calcType == NPC_NPC) {
			this._targetNpc.receiveDamage(this._npc, this._damage);
		}
	}

	/* ■■■■■■■■■■■■■■■ カウンターバリア ■■■■■■■■■■■■■■■ */

	// ■■■■ カウンターバリア時の攻撃モーション送信 ■■■■

	// ●●●● プレイヤーに計算結果を反映 ●●●●
	private final void commitPc() {
		if (this._calcType == NPC_PC) {
			this._targetPc.receiveDamage(this._npc, this._damage, false);
		}
	}

	// ■■■■ 相手の攻撃に対してカウンターバリアが有効かを判別 ■■■■
	@Override
	public final boolean isShortDistance() {
		boolean isShortDistance = true;
		if (this._calcType == NPC_PC) {
			final boolean isLongRange = this._npc.getLocation()
					.getTileLineDistance(
							new Point(this._targetX, this._targetY)) > 1;
			final int bowActId = this._npc.getNpcTemplate().getBowActId();
			// 距離が2以上、攻撃者の弓のアクションIDがある場合は遠攻撃
			if (isLongRange && bowActId > 0) {
				isShortDistance = false;
			}
		}
		return isShortDistance;
	}

	/*
	 * 武器を損傷させる。 対NPCの場合、損傷確率は10%とする。祝福武器は3%とする。
	 */
	/*
	 * private void damageNpcWeaponDurability() { final int chance = 10; final
	 * int bchance = 3;
	 *
	 * /* 損傷しないNPC、素手、損傷しない武器使用、SOF中の場合何もしない。
	 *//*
		 * if (_calcType != PC_NPC || _targetNpc.getNpcTemplate().is_hard() ==
		 * false || _weaponType == 0 || weapon.getItem().get_canbedmg() == 0 ||
		 * _pc.hasSkillEffect(SOUL_OF_FLAME)) { return; } // 通常の武器・呪われた武器 if
		 * ((_weaponBless == 1 || _weaponBless == 2) && ((Random.nextInt(100) +
		 * 1) < chance)) { // \f1あなたの%0が損傷しました。 _pc.sendPackets(new
		 * S_ServerMessage(268, weapon.getLogName()));
		 * _pc.getInventory().receiveDamage(weapon); } // 祝福された武器 if
		 * (_weaponBless == 0 && ((Random.nextInt(100) + 1) < bchance)) { //
		 * \f1あなたの%0が損傷しました。 _pc.sendPackets(new S_ServerMessage(268,
		 * weapon.getLogName())); _pc.getInventory().receiveDamage(weapon); } }
		 *
		 * /* バウンスアタックにより武器を損傷させる。 バウンスアタックの損傷確率は10%
		 */

	/**
	 * ＮＰＣのアンデッドの夜間攻撃力の変化
	 *
	 * @return
	 */
	private boolean isUndeadDamage() {
		boolean flag = false;
		final int undead = this._npc.getNpcTemplate().get_undead();
		final boolean isNight = L1GameTimeClock.getInstance().currentTime()
				.isNight();
		if (isNight) {
			switch (undead) {
			case 1:
			case 3:
			case 4:
				flag = true;
				break;
			}
		}
		return flag;
	}

	// ■■■■ カウンターバリアのダメージを反映 ■■■■
	/*
	 * public final void commitCounterBarrier() { final int damage =
	 * calcCounterBarrierDamage();
	 *
	 * if (damage == 0) { return; } if (_calcType == PC_PC ) {
	 * _pc.receiveDamage(_targetPc, damage, false); }else if (_calcType ==
	 * PC_NPC){ _targetPc.receiveDamage(_npc, damage, false); } else if
	 * (_calcType == NPC_PC) { _npc.receiveDamage(_targetPc, damage);
	 *
	 * } }
	 */
	public final void opqloTEST() {
		this._npc = this._targetNpc;
		this._targetPc = this._pc;
	}
}
